package com.byedu.focus;

import com.byedu.base.BaseService;
import com.byedu.domain.focus.FocusLogDO;
import com.byedu.domain.focus.FocusUserDO;
import com.byedu.domain.focus.vo.FocusLogVO;
import com.byedu.domain.focus.vo.FocusUserVO;
import com.byedu.mapper.focus.FocusLogMapper;
import com.byedu.mapper.focus.FocusUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by jason on 2017/5/14.
 */
@Service
public class FocusLogService extends BaseService {

    @Autowired
    FocusLogMapper focusLogMapper;
    @Autowired
    FocusUserMapper focusUserMapper;
    /**
     * @description 更新
     * @author chenxigui
     * @date  2017-05-14
     * @param focusLogDO
     * @return
     */
    public Integer updateFocusLogDO(FocusLogDO focusLogDO){
        return  focusLogMapper.updateFocusLogDO(focusLogDO);
    }

    /**
     * @description 查询用户
     * @author chenxigui
     * @date  2017-05-14
     * @param userId
     * @return
     */
    public List<FocusLogVO> getFocusLogDOByUserId(String userId){
        FocusUserVO focusUserVO = new FocusUserVO(focusUserMapper.getFoucUserByUserId(userId));
        List<FocusLogDO> focusLogDOList =focusLogMapper.getFocusLogDOByUserId(userId);
        List<FocusLogVO> focusLogVOList = new ArrayList<FocusLogVO>();
        for(FocusLogDO focusLogDO: focusLogDOList){
            FocusLogVO focusLogVO = new FocusLogVO(focusLogDO,focusUserVO);
            focusLogVOList.add(focusLogVO);
        }
        return  focusLogVOList;
    }

    public Integer addFocusLogDO(FocusLogDO focusLogDO){
        return  focusLogMapper.addFocusLogDO(focusLogDO);
    }

    public Integer delFocusLogDO(FocusLogDO focusLogDO) {
        return  focusLogMapper.delFocusLogDO(focusLogDO);
    }

    public List<FocusLogVO> getFocusLogDOList(){
        List<FocusUserDO> focusUserDOList = focusUserMapper.getFoucUserList();
        List<FocusLogDO> focusLogDOList =focusLogMapper.getFocusLogDOList();
        List<FocusLogVO> focusLogVOList = new ArrayList<FocusLogVO>();
        for(FocusLogDO focusLogDO: focusLogDOList){
            FocusUserVO focusUserVO = null;
            for(FocusUserDO focusUserDO: focusUserDOList) {
                if(focusUserDO.getId().equals(focusLogDO.getUserid())){
                    focusUserVO = new FocusUserVO(focusUserDO);
                    break;
                }
            }
            FocusLogVO focusLogVO = new FocusLogVO(focusLogDO,focusUserVO);
            focusLogVOList.add(focusLogVO);
        }
        return  focusLogVOList;
    }
}